function appendCodeKN(oldData, newData) {
    if (!newData.entities){
        return;
    }
    if (!oldData) oldData = { results: [{ data: [{ graph: { nodes: [], relationships: [] } }] }] };

    // Initialize directories for quick lookup
    const oldNodesDir = {};
    const oldRelationsDir = {};

    // ... existing code for initializing oldNodesDir and oldRelationsDir ...
    const oldNodes = oldData.results[0].data[0].graph.nodes;
    const oldRelations = oldData.results[0].data[0].graph.relationships;

    for (let i = 0; i < oldNodes.length; i++) {
        oldNodesDir[oldNodes[i].id] = oldNodes[i];
    }

    for (let i = 0; i < oldRelations.length; i++) {
        const key = oldRelations[i].startNode + "-" + oldRelations[i].endNode;
        oldRelationsDir[key] = oldRelations[i];
    }


    let userUnknowNodes=[];

    // Process new entities as nodes
    for (const entity of newData.entities) {
        const nodeId = entity.name;

        // Create node if it doesn't exist
        if (!oldNodesDir[nodeId]) {
            const newNode = {
                id: nodeId,
                labels: [nodeId],
                properties: {
                    name:nodeId
                }
            };

            // Add attributes as properties
            for (const attr of entity.attributes) {
                if (attr.name)
                    newNode.properties[attr.name] = "";
                else
                    newNode.properties[attr] = "";
            }

            oldNodes.push(newNode);
            oldNodesDir[nodeId] = newNode;
        }

        // Process relationships
        for (const rel of entity.relationships) {
            const relKey = entity.name + "-" + rel.target;

            const newRelation = {
                id: relKey,
                type: rel.type,
                startNode: entity.name,
                endNode: rel.target,
                properties: {}
            };

            userUnknowNodes.push(rel.target)

            oldRelations.push(newRelation);
            oldRelationsDir[relKey] = newRelation;
        }
    }

    // Remove duplicates from userUnknowNodes
    userUnknowNodes = [...new Set(userUnknowNodes)];

    // Process each unknown node
    for (const nodeName of userUnknowNodes) {
        // Check if node already exists
        if (!oldNodesDir[nodeName]) {
            // Create new node with empty properties and mark as unknown
            const newNode = {
                id: nodeName,
                labels: [nodeName],
                properties: {
                    isUnknown: true,  // Mark as unknown node
                    name:nodeName
                }
            };
            
            // Add to nodes directory and nodes array
            oldNodes.push(newNode);
            oldNodesDir[nodeName] = newNode;
        }
    }

    return oldData;
}